<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Task;
use App\Cart;
use App\Http\Requests;
use App\Repositories\TaskRepository;

class CartController extends Controller
{
    protected $carts;
    public function __construct(TaskRepository $carts)
    {
        $this->middleware('auth');

        $this->carts = $carts;
    }

    public function index(){
        return view('carts.index');
    }

    public function store(Request $request)
    {
        $this->validate($request, [
            'book_id' => 'required|max:255',
            'count' => 'required|max:255',
        ]);

        $request->user()->carts()->create([
            'book_id' => $request->book_id,
            'count' => (int)$request->count,

        ]);
        return redirect('/');
    }
}
